#import <Foundation/Foundation.h>
#import <objc/runtime.h>
#import <UIKit/UIApplication.h>
#import <SpringBoard/SBApplicationController.h>
#import <SpringBoard/SBApplication.h>
#import "PIDotView.h"


@implementation PIDotView

@synthesize color;

static CGFloat colors[] =
{
	1.0, 1.0, 1.0, 1.0,
//	1.0, 1.0, 1.0, 0.3
//	0.6, 0.6, 0.6, 0.6,
//	0.3, 0.3, 0.3, 0.3,
	0.0, 0.0, 0.0, 0.1
};

static CGFloat pi = 3.14159;


-(void)dealloc {
	[color release];
	
    [super dealloc];
}

-(void) drawRect:(CGRect) rect
{
	// Get a gradient across our set of mask colors
	CGColorSpaceRef rgb = CGColorSpaceCreateDeviceRGB();
	CGGradientRef gradient = CGGradientCreateWithColorComponents(rgb, colors, NULL, sizeof(colors)/(sizeof(colors[0])*3));
	CGColorSpaceRelease(rgb);
	
	// Set start and end point of the gradient to travel diagonally across the image
    CGPoint startPoint = CGPointMake(rect.origin.x * 0.25, rect.origin.y);
    CGPoint endPoint = CGPointMake(rect.origin.x + rect.size.width * 0.75, rect.origin.y + rect.size.height);
	
	CGContextRef context = UIGraphicsGetCurrentContext();
	[self.color set];
	
	// Define the path of the image as an arc to be used to clip the gradient to within the circle
    CGContextBeginPath(context);
	CGContextAddArc(context,
					rect.origin.x + rect.size.width / 2,
					rect.origin.y + rect.size.height / 2,
					rect.size.height / 2, 0,
					2 * pi, 0);
    CGContextClosePath (context);
    CGContextClip (context);
	
	// Fill the image with the background color
	CGContextFillEllipseInRect(context, rect);
	
	// Now apply the gradient across the image
	CGContextDrawLinearGradient(context, gradient, startPoint, endPoint, 0);
}

@end
